﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ZFMaster.Master" AutoEventWireup="true" CodeBehind="_sf.aspx.cs" Inherits="ZF.WS.test._sf" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

 <style>
 .divIFrame dl dt a{ display:block; float:left;  width:150px; cursor:pointer; line-height:24px;  height:24px; *padding-top:6px;}
 .divIFrame dt a img{ padding-top:1px; margin-left:5px;margin-right:5px; }
 .divIFrame dt a.active{  }
  
 .divIFrame dl dd{ display:none; padding:2px;}
 .divIFrame dl dd.active{ display:block;}
 </style>
 
<div id="msg">


</div>
 

<div class="board divIFrame">
    <dl>
        <dt>
        
       </dt>
  
    </dl>
    
     <div class="atemplate dn_">
       <a bind="{0}" name='{1}'>{1}<img src="/images/tab-close.gif" title="关闭" /></a>
    </div>
    <div class="ddtemplate dn_">
       <dd bind='{0}'><iframe src="_s.aspx?rk={0}"  frameborder="no" border="0" marginwidth="0"
        scrolling="no" marginheight="0" allowtransparency="yes"  style=" border:0px; width:100%; height:800px;"></iframe></dd>
    </div>
</div>




<script>
var memberId=<%=this.CurrentUser.MemberId %></script>
<script>


    $(function() {
        _keep();
         _getCall();
        _setTitleEvent("cc");
        _setTitleEvent("cc1");

    });
    function _setTitleEvent(key) {
        var divIFrame = $(".divIFrame");
       
        divIFrame.find(String.format("dt a[@bind='{0}']", key)).click(function() {
            divIFrame.find("dt a").removeClass("active");
            $(this).addClass("active");
            divIFrame.find("dd").removeClass("active");
            divIFrame.find(String.format("dd[@bind='{0}']", $(this).attr("bind"))).addClass("active");
        });
        divIFrame.find(String.format("dt a[@bind='{0}'] img", key)).click(function() {
            var cr = confirm(String.format("是否关闭与{0}的对话", $(this.parentNode).attr("name")));
            if (cr) {
                var active = $(this.parentNode).hasClass("active");
                var key = $(this.parentNode).attr("bind");
                $.ajax({
                    type: "POST",
                    data: $.toJSON({ memberId: memberId, roomKey: key }),
                    contentType: "application/json",
                    url: "/WSChat.asmx/Out",
                    cache: false,
                    async: false,
                    success: function(msg) {
                        var msg = $.evalJSON(msg).d;
                        
                    }
                });


                divIFrame.find(String.format("dd[@bind='{0}']", $(this.parentNode).attr("bind"))).remove();
                $(this.parentNode).remove();
                if (active) {
                    if (divIFrame.find("dt a").length > 0)
                        divIFrame.find("dt a")[0].click();
                }


            }
            return false;
        });
        if (divIFrame.find("dt a.active").length == 0 &&
            divIFrame.find("dt a").length > 0) {
            divIFrame.find("dt a")[0].click()
        }
    }
    var i_getCall = 1
    var i_keep = 5;
    var _getCallFirst = true;
    function _getCall() {
        i_getCall--
        if (i_getCall == 0) {
            i_getCall = 5;
            setTimeout("_getCall()", 1000);
            $.ajax({
                type: "POST",
                data: $.toJSON({ memberId: memberId, getAll: _getCallFirst }),
                contentType: "application/json",
                url: "/WSChat.asmx/RecCall",
                cache: false,
                async: false,
                success: function(msg) {
                    var msg = $.evalJSON(msg).d;
                    if (msg.length > 0) {
                        var ddtemplate = $(".divIFrame .ddtemplate").html();
                        var atemplate = $(".divIFrame .atemplate").html();
                        $(msg).each(function() {
                            $(".divIFrame dl").append(String.format(ddtemplate, this.RoomKey));
                            $(".divIFrame dt").append(String.format(atemplate, this.RoomKey, this.FromMember));
                            _setTitleEvent(this.RoomKey);
                        });
                    }
                }
            });
            _getCallFirst = false;
        } else
            setTimeout("_getCall()", 1000);
    }
    
    
    
    function _keep() {
        i_keep--
        if (i_keep == 0) {
            i_keep = 5;
            setTimeout("_keep()", 1000);
            $.ajax({
                type: "POST",
                data: String.format("{memberId:{0}}", memberId),
                contentType: "application/json",
                url: "/WSChat.asmx/Keep",
                cache: false,
                async: false,
                success: function(msg) {
                   
                }
            });
        }else
            setTimeout("_keep()", 1000);

    }
</script>



</asp:Content>
